package cloud.xlh.digital_power_order.enums;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/10/9 9:34
 * @ Description:
 */
public enum OrderStatusEnum {
    INIT(9, "初始化"),
    LOCAL_FAIL(1, "本地生成失败"),
    REMOTE_EXCEPTION(2, "远程生成异常"),
    REMOTE_FAIL(3, "远程生成失败"),
    REMOTE_SUCCESS(4, "远程生成成功"),
    PAY_EXCEPTION(5, "支付异常"),
    PAY_FAIL(6, "支付失败"),
    PAY_SUCCESS(0, "支付成功"),
    REFUND_APPLYING(7, "退款申请中"),
    REFUND_FAIL(8, "退款失败"),
    REFUND_EXCEPTION(9, "退款异常");

    private static final Set<Integer> enumSet = new HashSet<>(3);

    static {
        Arrays.asList(OrderStatusEnum.values()).forEach(e -> enumSet.add(e.getCode()));
    }

    public static boolean hasEnum(Integer code) {
        return enumSet.contains(code);
    }


    private Integer code;

    private String desc;

    OrderStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDesc(Integer code) {
        OrderStatusEnum[] values = values();
        if (code == null)
            return null;
        for (OrderStatusEnum value : values) {
            if (value.code.equals(code)) {
                return value.desc;
            }
        }
        return null;
    }
}
